package vapu.examples;
import im.composer.audioservers.adapter.CallableAudioServer;
import im.composer.audioservers.asio.AsioAudioServer;
import im.composer.media.sound.render.SourcePlayer;
import im.composer.midi.MidiCable;
import im.composer.vapu.VAPU;
import im.composer.vapu.adapter.GervillSynth;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.sound.midi.ShortMessage;

import org.jaudiolibs.audioservers.AudioConfiguration;
import org.jaudiolibs.audioservers.AudioServer;
import org.jaudiolibs.audioservers.javasound.JSAudioServerProvider;

import vapu.examples.dreinulldrei.DreiNullDrei;
import vapu.examples.liquinth.LiquinthVST;

public class SynthExample {

	public static void main(String[] args) throws Throwable {
		AudioConfiguration conf = new AudioConfiguration(48000, 0, 2, 512, true);
		MidiDebug mbd = new MidiDebug();
		VAPU synth;
//		synth = new GervillSynth();
//		synth = new DreiNullDrei();
		synth = new LiquinthVST();
		mbd.setReceiver(synth);
		SourcePlayer player = new SourcePlayer();
		player.addSource(synth);
		MidiCable cable = new MidiCable("iCON iKEY V2.03", mbd);
//		AudioServer server = new JSAudioServerProvider().createServer(conf, player);
		AudioServer server = AsioAudioServer.createServer(conf, player);
		ExecutorService exec = Executors.newCachedThreadPool();
		CallableAudioServer.submit(exec, server);
		System.out.println("ready!");
		Thread.sleep(500);
		mbd.send(new ShortMessage(ShortMessage.NOTE_ON,0,0,1), 0);
		mbd.send(new ShortMessage(ShortMessage.NOTE_OFF,0,0,0), 0);
	}

}
